﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Papaleguas.Library;
using System.Globalization;

namespace Papaleguas.LayoutFileCompare
{
    public partial class Compare : Form
    {
        public Compare()
        {
            InitializeComponent();
            Comparar();
        }

        private void Comparar()
        {
            int ctlIndex = 0;
            richTextBox1.Font = new Font("Courier New", 20);
            Font oldFont = richTextBox1.SelectionFont;
            Color oldFontColor = richTextBox1.SelectionColor;
            Color oldBackColor = richTextBox1.SelectionBackColor;
            CampoValorServices campoValorServices = new CampoValorServices();
            foreach (Dados.CampoRow campo in DataWrapper.Instance.BaseDados.Campo)
            {
                richTextBox1.Select(ctlIndex, campo.Tamanho);
                richTextBox1.SelectionColor = Color.White;

                int argb = Int32.Parse(campo.Cor.Replace("#", ""), NumberStyles.HexNumber);
                Color clr = Color.FromArgb(argb);
                richTextBox1.SelectionBackColor = clr;
                campoValorServices.RegistrarCampoValor(campo, richTextBox1.SelectedText);
                ctlIndex += campo.Tamanho;
            }

            richTextBox1.Select(0, 0);
            richTextBox1.SelectionFont = oldFont;
            richTextBox1.SelectionColor = oldFontColor;
            richTextBox1.SelectionBackColor = oldBackColor;

            dataGridView1.DataSource = campoValorServices.ListarCampoValores();
        }

        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "validoDataGridViewCheckBoxColumn")
            {
                if (e.Value != null)
                {
                    if (!(bool)e.Value) e.CellStyle.BackColor = Color.Red;
                }
            }
        }
    }
}
